<!DOCTYPE html>
<html>

<head lang="en">
    <title>找攻略</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategy.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script>
        $(function () {
            //地区id变量
            var placeId;
            //攻略推荐
            $.get("/travels/commends", {pageSize: 1, type: 3}, function (data) {
                var commendData = data.list[0];
                console.log(commendData);
                $(".commend").renderValues(commendData, {
                    //给a标签赋予href属性
                    getHref: function (item, value) {
                        var url = $(item).data("href");
                        $(item).attr("href", url + value);
                    }
                });
            });
            //当季推荐
            $.get("/strategies", {state: 1, pageSize: 0}, function (data) {
                $(".strategyCommend").renderValues(data, {
                    //给a标签赋予href属性
                    getHref: function (item, value) {
                        var url = $(item).data("href");
                        $(item).attr("href", url + value);
                    }
                });
            });
            //获取所有推荐地区
            $.get("/regions/1",function (data) {
                //地区拼接到指定位置
                var tab = "";
                var tabContent = "";
                $.each(data,function (index,ele) {
                    tab += '<li class="nav-item"><a class="nav-link" data-placeid='+ele.id+' data-toggle="pill" href="#pills-'+ele.id+'">'+ele.name+'</a></li>';
                    tabContent += '<div class="tab-pane fade" id="pills-'+ele.id+'"></div>';
                });
                $(tab).appendTo("#pills-tab");
                $(tabContent).appendTo("#pills-tabContent");
                //设置地址栏的点击事件
                $(".nav-link").click(function () {
                    currentPage = 2;
                    pages = 2;
                    //获取地区id
                    placeId = $(this).data("placeid");
                    if (placeId) {
                        //根据地区id查询攻略,并拼接到相应位置
                        $.get("/regions/"+placeId+"/strategies",function (data) {
                            $("#pills-"+placeId).html("");
                            $("#pills-"+placeId).append(data);
                        },"html")
                    }
                });
            });
            //分页操作
            //当前页从第二页开始,第一页是通过模板拼接得到的
            var currentPage = 2;
            var pages = 2;
            var flag = false;

            //查询方法
            function query() {
                //获取游记信息,渲染
                if (flag) {
                    return;
                }
                    flag = true;
                    $.get("/regions/"+placeId+"/strategies", {currentPage: currentPage}, function (data) {
                        console.log(data);
                        $.each(data.list,function (index,ele) {
                            //获取模板并赋值
                            console.log(ele);
                            var temp = $("#template .mb").clone(true);
                            $(temp).find("a").attr("href",'/strategyCatalogs.html?strategyId='+ele.id);
                            $(temp).find("img").attr("src",ele.coverUrl);
                            $(temp).find("span").html(ele.title);
                            $(temp).appendTo(".classify");
                            //$(".classify").append(temp);
                        });
                        currentPage++;
                        pages = data.pages;
                        flag = false;
                    },"json");

            }
            //分页
            $(window).scroll(function () {
                if ($(window).height() + $(document).scrollTop() + 0.3 >= $(document).height()) {
                    if (currentPage <= pages && placeId) {
                        query();
                    } else {
                        $(document).dialog({
                            type: 'notice',
                            infoText: '亲,已经到底部啦!',
                            autoClose: 1500,
                            position: 'bottom'  // center: 居中; bottom: 底部
                        });
                    }
                }
            });
        })
    </script>
</head>

<body>
<!-- 全部攻略模板 -->
<div id="template" style="display: none">
    <div class="col-6 mb">
        <a>
            <img class="float-left ">
            <div class="classify-text">
                <span></span>
                <p>0人收藏</p>
            </div>
        </a>
    </div>
</div>

<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="找攻略">
            </div>
        </div>
    </div>
</div>
<!-- 地区推荐栏 -->
<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab" role="tablist">
    <li class="nav-item">
        <a class="nav-link active show" data-toggle="pill" href="#pills-top">
            <span style="font-weight: bold;">推荐</span>
        </a>
    </li>
</ul>
<div class="tab-content" id="pills-tabContent">
    <div class="tab-pane fade active show" id="pills-top">
        <!-- 游记推荐 -->
        <div class="container commend">
            <a data-href="travelContent.html?travelId=" render-key="travelId" render-fun="getHref">
                <img render-src="coverUrl">
                <p render-html="title"></p>
            </a>
        </div>
        <hr>
        <!-- 推荐页面的当季推荐 -->
        <div class="container strategyCommend">
            <h6>当季推荐</h6>
            <div class="row hot" render-loop="list">
                <div class="col-4">
                    <a data-href="strategyCatalogs.html?strategyId=" render-key="list.id" render-fun="getHref">
                        <img render-src="list.coverUrl">
                        <p render-html="list.title"></p>
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>


</body>

</html>